home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2003 November A / PCWK1103A.iso / ABBYY FineReader 7.0 PRO / data1.cab / gs_type1.ps < prev    next >
Text File  |  2002-02-23  |  7KB  |  183 lines

  1. %    Copyright (C) 1994, 2000 Aladdin Enterprises.  All rights reserved.
  2. % This software is provided AS-IS with no warranty, either express or
  3. % implied.
  4. % This software is distributed under license and may not be copied,
  5. % modified or distributed except as expressly authorized under the terms
  6. % of the license contained in the file LICENSE in this distribution.
  7. % For more information about licensing, please refer to
  8. % http://www.ghostscript.com/licensing/. For information on
  9. % commercial licensing, go to http://www.artifex.com/licensing/ or
  10. % contact Artifex Software, Inc., 101 Lucas Valley Road #110,
  11. % San Rafael, CA  94903, U.S.A., +1(415)492-9861.
  12.  
  13. % $Id: gs_type1.ps,v 1.5.2.1 2002/02/22 19:45:55 ray Exp $
  14. % Type 1 font support code.
  15.  
  16. % The standard representation for PostScript compatible fonts is described
  17. % in the book "Adobe Type 1 Font Format", published by Adobe Systems Inc.
  18.  
  19. % Define an augmented version of .buildfont1 that inserts UnderlinePosition
  20. % and UnderlineThickness entries in FontInfo if they aren't there already,
  21. % and FontBBox isn't degenerate.
  22. % (This works around the incorrect assumption, made by many word processors,
  23. % that these entries are present in the built-in fonts.)
  24. /.buildfont1
  25.  {
  26.    false 1 index /FontBBox .knownget {
  27.      { 0 ne { not exit } if } forall
  28.    } if
  29.    { dup /FontInfo known not
  30.       { .growfontdict dup /FontInfo 2 dict put }
  31.      if
  32.      dup dup /FontInfo get dup dup
  33.      /UnderlinePosition known exch /UnderlineThickness known and
  34.       { pop pop        % entries already present
  35.       }
  36.       { dup length 2 add dict .copydict
  37.         dup /UnderlinePosition known not
  38.          { dup /UnderlinePosition 3 index /FontBBox .knownget
  39.             { 1 get 2 div }            % 1/2 the font descent
  40.         { -100 } ifelse put
  41.          }
  42.         if
  43.         dup /UnderlineThickness known not
  44.          { dup /UnderlineThickness 3 index /FontBBox .knownget
  45.             { dup 3 get exch 1 get sub 20 div }    % 1/20 the font height
  46.             { 50 } ifelse put
  47.          }
  48.         if
  49.         1 index /FontInfo get wcheck not { readonly } if
  50.         /FontInfo exch put
  51.       }
  52.      ifelse
  53.    } if
  54.    //.buildfont1
  55.  } bind def
  56. % If the diskfont feature isn't included, define a dummy .loadfontdict.
  57. /.loadfontdict where
  58.  { pop }
  59.  { /.loadfontdict 0 dict readonly def }
  60. ifelse
  61. /.loadfontfile        % <file> .loadfontfile -
  62.  { mark exch
  63.    DISKFONTS { .loadfontdict begin } if
  64.     % In order to load fonts reliably, we should push systemdict
  65.     % here.  However, Ed Taft says that Adobe implementations
  66.     % push userdict and nothing else!
  67.     % We really would just like systemdict on the stack,
  68.     % but fonts produced by Fontographer require a writable dictionary.
  69.     % However, we can't use any of the other well-known dictionaries
  70.     % (such as userdict), since the whole point of pushing systemdict
  71.     % is to make sure that nothing important has been redefined.
  72.    userdict begin
  73.     % We can't just use `run', because we want to check for .PFB files.
  74.    currentpacking
  75.     { false setpacking .loadfont1 true setpacking }
  76.     { .loadfont1 }
  77.    ifelse end
  78.     { stop } if
  79.    DISKFONTS { end } if
  80.    cleartomark
  81.  } bind def
  82. /.loadfont1 {        % <file> .loadfont1 <errorflag>
  83.   {    % We would like to use `false /PFBDecode filter',
  84.     % but this occasionally produces a whitespace character as
  85.     % the first of an eexec section, so we can't do it.
  86.     % Also, since the real input file never reaches EOF if we are using
  87.     % a PFBDecode filter (the filter stops just after reading the last
  88.     % character), we must explicitly close the real file in this case.
  89.     % Since the file might leave garbage on the operand stack,
  90.     % we have to create a procedure to close the file reliably.
  91.     dup read not { -1 } if
  92.     2 copy unread 16#80 eq {
  93.     dup true /PFBDecode filter cvx
  94.     exch .currentresourcefile eq {
  95.       dup /.execasresource .systemvar
  96.     } {
  97.       {exec}
  98.     } ifelse
  99.     2 index cvlit
  100.     /closefile .systemvar 3 .execn
  101.       } {
  102.     cvx exec
  103.     } ifelse
  104.   } stopped
  105. } bind def
  106.  
  107. % Here are the BuildChar and BuildGlyph implementation for Type 1 fonts.
  108. % The names %Type1BuildChar and %Type1BuildGlyph are known to the interpreter.
  109. % The real work is done in an operator:
  110. %    <font> <code|name> <name> <charstring> .type1execchar -
  111.  
  112. (%Type1BuildChar)  cvn {    % <font> <code> %Type1BuildChar -
  113.   1 index /Encoding get 1 index get .type1build .type1execchar
  114. } bind def
  115. (%Type1BuildGlyph) cvn {    % <font> <name> %Type1BuildGlyph -
  116.   dup .type1build .type1execchar
  117. } bind def
  118. % Note: this procedure is used for both Type 1 and Type 2 fonts.
  119. /.type1build {        % <font> <code|name> <name> .type1build
  120.             %   <font> <code|name> <name> <charstring>
  121.   2 index begin
  122.     dup CharStrings exch .knownget not {
  123.       2 copy eq { exch pop /.notdef exch } if
  124.        QUIET not
  125.     { (Substituting .notdef for ) print = flush }
  126.     { pop }
  127.        ifelse
  128.        /.notdef CharStrings /.notdef get
  129.     } if
  130.   end
  131. } bind def
  132. % CCRun is an undocumented procedure provided for Type 4 and Type 0 fonts.
  133. 1183615869 internaldict begin
  134. % Apparently there are two different argument lists for CCRun.
  135. % Handling the one with the extra Private dictionary requires fabricating
  136. % a Type 1 font on the fly, since we aren't currently prepared to parse the
  137. % dictionary any other way.
  138. /CCRun {    % <font> <code|name> <charstring> CCRun -
  139.         % <font> <code|name> <charstring> <Private> CCRun -
  140.   dup type /dicttype eq {
  141.     dup 4 index /Private .knownget { ne } { pop true } ifelse {
  142.         % The Private dictionary was supplied, and is different
  143.         % from the Private dictionary of the font.  Fabricate a
  144.         % Type 1 font with this Private dictionary.  Most of the
  145.         % font entries are arbitrary or not needed.
  146.       .currentglobal false .setglobal 10 dict exch .setglobal begin
  147.     /Private exch def
  148.     /FontType 1 def
  149.     /FontMatrix 3 index /FontMatrix get def
  150.     /Encoding 3 index /Encoding .knownget not { StandardEncoding } if def
  151.     /FontBBox 3 index /FontBBox .knownget not { {0 0 0 0} } if def
  152.     /PaintType 0 def
  153.     /CharStrings 1 dict dup /.notdef () put def
  154.       3 -1 roll pop () currentdict end .buildfont1 exch pop 3 1 roll
  155.     } {
  156.       pop
  157.     } ifelse
  158.   } if
  159.   1 index dup type /integertype eq {
  160.     3 index /Encoding get exch get
  161.   } if exch .type1execchar
  162. } bind def
  163. end
  164.  
  165. % Register the font types for definefont.
  166. buildfontdict 1 /.buildfont1 cvx put
  167. buildfontdict 4 /.buildfont4 cvx put
  168.  
  169. % Add Type 2 support if applicable.
  170. /.buildfont2 where not { (%END2) .skipeof } if
  171. pop
  172. (%Type2BuildChar)  cvn {    % <font> <code> %Type2BuildChar -
  173.   1 index /Encoding get 1 index get .type1build .type2execchar
  174. } bind def
  175. (%Type2BuildGlyph) cvn {    % <font> <name> %Type2BuildGlyph -
  176.   dup .type1build .type2execchar
  177. } bind def
  178. buildfontdict 2 /.buildfont2 cvx put
  179. %END2
  180.